using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using FerrSimplicity;

namespace SampleApp
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch           spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
        protected override void Initialize()
        {
            // add any game states we want to be available for the game
            SystemGameStates.Instance.AddState(new GameState(this));

            // set a game state as active
            SystemGameStates.Instance.StartState<GameState>();

            base.Initialize();
        }

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            FerrGlobals.SpriteBatch = spriteBatch;

            // Add a default font to the font style manager, so we can draw text stuff to the screen.
            ManagerFontStyle.Instance.AddStyle("Default", Content.Load<SpriteFont>("DefaultFont"), Color.White);
        }

        protected override void Update(GameTime gameTime)
        {
            // update all the managers that we care about
            SystemTime      .Instance.Update(gameTime);
            SystemInput     .Instance.Update(gameTime);
            SystemGameStates.Instance.Update(gameTime);

            // Allows the game to exit
            if (SystemInput.Instance.KeyJustDown(Keys.Escape))
            {
                SystemInput.Instance.EatKey(Keys.Escape);
                this.Exit();
            }

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin(SpriteSortMode.BackToFront, null, null, null, null, null, ManagerCameras.Instance.Transform);
            base.Draw(gameTime);
            SystemGameStates.Instance.Draw(gameTime);
            SystemText      .Instance.Draw(gameTime);
            spriteBatch.End();
        }
    }
}
